home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-09-25 | 6.9 KB | 246 lines |
- //
- // avatar.java
- // action, set avatar color, smooth move
- //
- // (c) Copyright 1996 Sony Corporation. All rights reserved.
-
- import vs.*;
- import vrml.*;
- import vrml.field.*;
- import vrml.node.*;
-
- public class avatar extends Script {
- private SFFloat value;
- private SFTime helloStart;
- private SFTime smileStart;
- private SFTime woooStart;
- private SFTime waoStart;
- private SFTime ummStart;
- private SFTime sadStart;
- private SFBool timerOn;
- private SFTime timerStart;
- private SFBool timerwOn;
- private SFTime timerwStart;
- private MFVec3f avatarTrans;
- private SFVec3f avatarDirect;
- private SFRotation avatarRot;
-
- private static String ActionList[] = {
- "Hello",
- "Smile",
- "Wao",
- "Umm",
- "Wooo",
- "Sad",
- "Bye",
- "Sleep",
- "Normal", };
-
-
- private float tmpArray[][];
- private double vector[];
- private float dist[];
- private double length;
- private boolean start = true;
- private float key = 0.0f;
- private int parity = 0;
- private int flag = 0;
- private int counter = 0;
-
- // to change color
- final int PARTS_MAX = 18;
- SFColor newColor[] = new SFColor [ PARTS_MAX ];
- final int cBase = '0';
- final int COLOR_MAX = 18;
-
-
- public void initialize() {
- String str;
-
- value = (SFFloat) getEventOut("value");
- helloStart = (SFTime) getEventOut("helloStart");
- smileStart = (SFTime) getEventOut("smileStart");
- woooStart = (SFTime) getEventOut("woooStart");
- waoStart = (SFTime) getEventOut("waoStart");
- ummStart = (SFTime) getEventOut("ummStart");
- sadStart = (SFTime) getEventOut("sadStart");
- timerOn = (SFBool) getEventOut("timerOn");
- timerStart = (SFTime) getEventOut("timerStart");
- timerwOn = (SFBool) getEventOut("timerwOn");
- timerwStart = (SFTime) getEventOut("timerwStart");
- avatarTrans = (MFVec3f) getEventOut("avatarTrans");
- avatarDirect = (SFVec3f) getEventOut("avatarDirect");
- avatarRot = (SFRotation) getEventOut("avatarRot");
-
- tmpArray = new float[2][3];
- vector = new double[3];
- dist = new float[3];
-
- for( int i = 0; i < PARTS_MAX; i++ ){
- str = "part" + i;
- newColor[ i ] = (SFColor)getEventOut( str );
- }
- }
-
- public void timeOut(ConstSFTime t, double now) {
- if(parity == 1) {
- key = 0.0f;
- value.setValue(key);
- parity = 0;
- } else if ( key == 0.0f) {
- parity = 0;
- } else {
- parity = 1;
- }
- }
-
- public void sonyAvatarPosture(ConstSFString action, double t){
- String actionName = action.getValue();
- if (actionName.equals( ActionList[0])) {
- key = 0.04f;
- value.setValue(key);
- helloStart.setValue(t);
- } else if ( actionName.equals( ActionList[1])) {
- key = 0.05f;
- value.setValue(key);
- smileStart.setValue(t);
- } else if ( actionName.equals( ActionList[2])) {
- key = 0.07f;
- value.setValue(key);
- waoStart.setValue(t);
- } else if ( actionName.equals( ActionList[3])) {
- key = 0.06f;
- value.setValue(key);
- woooStart.setValue(t);
- } else if ( actionName.equals( ActionList[4])) {
- key = 0.08f;
- value.setValue(key);
- ummStart.setValue(t);
- } else if ( actionName.equals( ActionList[5])) {
- key = 0.09f;
- value.setValue(key);
- sadStart.setValue(t);
- } else if ( actionName.equals( ActionList[6])) {
- key = 0.12f;
- value.setValue(key);
- } else if ( actionName.equals( ActionList[7])) {
- key = 0.13f;
- value.setValue(key);
- } else if ( actionName.equals( ActionList[8])) {
- key = 0.0f;
- value.setValue(key);
- } else {
- key = 0.0f;
- value.setValue(key);
- }
- if (key == 0.13f ) {
- } else {
- timerStart.setValue(t);
- timerOn.setValue(start);
- }
- }
-
- public void timewOut(ConstSFTime t, double now) {
- if(counter == 1) {
- flag = 0;
- } else if (flag == 0) {
- counter = 0;
- } else {
- counter = 1;
- }
- }
-
- public void sonyAvatarVector(ConstMFVec3f avtPosition, double t){
- avtPosition.getValue(tmpArray);
-
- vector[0] = (tmpArray[1][0] - tmpArray[0][0]);
- vector[1] = (tmpArray[1][1] - tmpArray[0][1]);
- vector[2] = (tmpArray[1][2] - tmpArray[0][2]);
-
- dist[0] = tmpArray[1][0];
- dist[1] = tmpArray[1][1];
- dist[2] = tmpArray[1][2];
-
- length = Math.sqrt(vector[0]*vector[0] + vector[1]*vector[1] + vector[2]*vector[2]);
-
- if (false) {
- if (flag == 0) {
- avatarTrans.setValue(tmpArray);
- timerwStart.setValue(t);
- timerwOn.setValue(start);
- flag = 1;
- counter = 0;
- }
- } else {
- avatarDirect.setValue(dist);
- }
- }
-
- public void sonyAvatarAttribute(ConstSFString action, double t){
- String actionName = action.getValue();
- String colorstr = actionName.substring(8);
-
- if (actionName.startsWith("sleep:1 ")) {
- key = 0.13f;
- } else {
- key = 0.0f;
- }
- value.setValue(key);
-
- // set avater color
- setcolor( colorstr );
- }
-
- // set color to avater parts
- public void setcolor ( String colorString ){
- String str;
- SFInt32 colorNo;
- float f[] = new float[ 3 ];
-
- // decode
- if ( colorString.length() < PARTS_MAX ){
- // default color
- System.out.println ( "default color " );
-
- }
- else{
- System.out.println ( "set color: " + colorString );
- for ( int i = 0; i < PARTS_MAX; i++ ){
- int decode = (int) colorString.charAt( i ) - cBase;
-
- // set diffuse color
- if ( decode < COLOR_MAX ){
- f = GenerateColor.getSFColor( decode );
- newColor[ i ].setValue( f );
- }
- }
- }
- }
-
- public void processEvent(Event e) {
- String name = e.getName();
-
- if (name.equals("sonyAvatarPosture")) {
- sonyAvatarPosture((ConstSFString)e.getValue(), e.getTimeStamp());
- } else if (name.equals("sonyAvatarVector")) {
- sonyAvatarVector((ConstMFVec3f)e.getValue(), e.getTimeStamp());
- } else if (name.equals("timeOut")) {
- timeOut((ConstSFTime)e.getValue(), e.getTimeStamp());
- } else if (name.equals("timewOut")) {
- timewOut((ConstSFTime)e.getValue(), e.getTimeStamp());
- } else if (name.equals("sonyAvatarAttribute")) {
- sonyAvatarAttribute((ConstSFString)e.getValue(), e.getTimeStamp());
- }
-
- }
-
- }
-
-
-
-
-
-
-
-
-